package sk.naive.talker.command;

import sk.naive.talker.persistence.PersistenceException;
import sk.naive.talker.props.*;
import sk.naive.talker.User;

import java.rmi.RemoteException;
import java.util.*;

/**
 * Macro.
 *
 * @author <a href="mailto:virgo@naive.deepblue.sk">Richard "Virgo" Richter</a>
 * @version $Revision: 1.4 $ $Date: 2004/11/14 18:47:35 $
 */
public class Macro extends AbstractSetCommand {
	protected String setValue(String key, String value) throws RemoteException, PropertyStoreException, PersistenceException {
		Map<String,String> macros = (Map<String,String>) store().get(getPropertyName());
		if (value != null && value.length() > 0) {
			macros.put(key, value);
		} else {
			value = null;
			macros.remove(key);
		}
		store().set(getPropertyName(), macros);
		return value;
	}

	protected Set<String> getValidValues(String key) throws RemoteException {
		return null;
	}

	protected String getValue(String key) throws RemoteException, PropertyStoreException {
		return ((Map<String,String>) store().get(getPropertyName())).get(key);
	}

	protected Set<String> settable() {
		return null;
	}

	protected Set<String> setUpKeys() throws RemoteException, PropertyStoreException {
		return ((Map<String,String>) store().get(getPropertyName())).keySet();
	}

	protected String getPropertyName() {
		return User.UPROP_MACROS;
	}

	protected PropertyStore store() {
		return user;
	}

	protected String getPropertyNotFoundKey() {
		return "macro.notFound";
	}

	protected String getInvalidValueKey() {
		return "macro.invalidValue";
	}

	protected String getVoidSetKey() {
		return "macro.propVoidSet";
	}

	protected String getSuccesfulSetKey() {
		return "macro.propSet";
	}

	protected String getCurrentValueKey() {
		return "macro.currentValue";
	}

	protected String getHeaderKey() {
		return "macro.head";
	}

	protected String getFooterKey() {
		return "macro.tail";
	}
}
